package com.itmq;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class ProducerDemo {
    public static void main(String[] args) throws Exception {
        //创建连接工厂
        ActiveMQConnectionFactory connectionFactory=new ActiveMQConnectionFactory("tcp://192.168.101.128:61616");
        //通过工厂获取连接，并开启连接
        Connection connection = connectionFactory.createConnection();
        connection.start();
        //通过连接获取会话session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        //创建目的地
       // Queue queue = session.createQueue("queue_107");
        Topic topic = session.createTopic("topic_107");
        //创建消息生产者
        MessageProducer producer = session.createProducer(topic);
        //创建消息
        TextMessage message = session.createTextMessage("这是一个主题");
        //发送消息
        producer.send(message);
        session.close();
        connection.close();


    }
}
